package com.example.demo;

import com.example.demo.entity.Student;
import com.example.demo.entity.StudentCourse;
import com.example.demo.mapper.StudentCourseMapper;
import com.example.demo.util.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TestStudentCourseEntity {
    public static void main(String[] args) {
        SqlSession session = MyBatisUtils.getSession();
        StudentCourseMapper mapper = session.getMapper(StudentCourseMapper.class);

        List<Student> studentList = mapper.getAllStudentsWithCourseRecords();

        System.out.println("=== 学生及课程记录 ===");
        for (Student s : studentList) {
            System.out.println("学生：" + s.getName());
            for (StudentCourse sc : s.getCourseRecords()) {
                System.out.println("  - 课程：" + sc.getCourse().getName()
                        + "，成绩：" + sc.getScore()
                        + "，选课时间：" + sc.getSelectedTime());
            }
        }

        session.close();
    }
}